<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="招标编号" prop="sectionId">
        <el-input v-model="queryParams.sectionId" placeholder="请输入招标编号" clearable @clear="handleQuery"  @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="招标名称" prop="sectionName">
        <el-input v-model="queryParams.sectionName" placeholder="请输入招标名称" clearable @clear="handleQuery"  @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="招标类别" prop="bidcategory" v-if="userInfo.userId == 127">
        <el-select v-model="queryParams.bidcategory" clearable @clear="handleQuery" @change="handleQuery" placeholder="请选择招标类别">
          <el-option
            v-for="dict in dict.type.sys_bidcategory"
            :key="dict.value"
            :label="dict.label"
            :value="Number(dict.value)">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="组织方式" prop="bidmethod">
        <el-select v-model="queryParams.bidmethod" clearable @clear="handleQuery" @change="handleQuery" placeholder="请选择组织方式">
          <el-option
            v-for="dict in dict.type.sys_bidmethos"
            :key="dict.value"
            :label="dict.label"
            :value="Number(dict.value)">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="开标时间" prop="open">
        <el-date-picker clearable @clear="handleQuery" v-model="queryParams.open" type="date" value-format="yyyy-MM-dd" @change="handleQuery" placeholder="请选择开标时间"></el-date-picker>
      </el-form-item>
      <!-- <el-form-item label="招标进度" prop="sectionProgress">
        <el-select v-model="queryParams.sectionProgress" clearable @clear="handleQuery" @change="handleQuery" placeholder="请选择招标进度">
          <el-option
            v-for="dict in dict.type.section_progress"
            :key="dict.value"
            :label="dict.label"
            :value="Number(dict.value)">
          </el-option>
        </el-select>
      </el-form-item> -->
      <el-form-item>

        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="sectionList" border>
      <el-table-column label="序号" type="index" fixed width="55" align="center" :index="indexMethod" />
      <el-table-column label="部门" fixed align="center" prop="projectInfo.deptName" width="200" show-overflow-tooltip />
      <el-table-column label="项目负责人" fixed align="center" prop="projectInfo.assistant"  width="120" show-overflow-tooltip />
      <el-table-column label="招标编号" align="center" prop="sectionId"  width="160" show-overflow-tooltip>
        <template slot-scope="scope">
          <span @dblclick="copyText(scope.row.sectionId)">{{ scope.row.sectionId }}</span>
        </template>
      </el-table-column>
      <el-table-column label="招标名称" align="center" prop="sectionName"  width="200" show-overflow-tooltip>
        <template slot-scope="scope">
          <span @dblclick="copyText(scope.row.sectionName)">{{ scope.row.sectionName }}</span>
        </template>
      </el-table-column>
      <el-table-column label="招标类别" align="center"  width="120">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_bidcategory" :value="scope.row.projectInfo.bidcategory"/>
        </template>
      </el-table-column>
      <el-table-column label="组织方式" align="center"  width="120">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_bidmethos" :value="scope.row.bidmethod"/>
        </template>
      </el-table-column>
      <el-table-column label="开标时间" align="center" prop="open" width="140" show-overflow-tooltip>
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.open, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="招标进度" align="center" width="120" show-overflow-tooltip>
        <template slot-scope="scope">
          <el-tag :type="scope.row.sectionProgress === 8 || scope.row.sectionProgress === 9 ? 'danger' : (scope.row.sectionProgress === 7 ? 'success' : '' )">{{ selectDictLabel(dict.type.section_progress, scope.row.sectionProgress) }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="中标单位" align="center" width="220" show-overflow-tooltip>
        <template slot-scope="scope">
          <span>{{ scope.row.winCompany }}</span>
        </template>
      </el-table-column>
      <el-table-column label="中标金额" align="center" width="120" show-overflow-tooltip>
        <template slot-scope="scope">
          <span>{{ scope.row.preMoney }} 元</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" fixed="right" width="100" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleDetail(scope.row)"
            v-hasPermi="['system:section:detail']"
          >查看</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 发布公告 -->
    <el-dialog :title="title" :visible.sync="open" width="900px" append-to-body :close-on-click-modal="false">
      <el-form ref="sectionForm" :rules="rules" :model="form" label-width="96px">
        <el-row>
          <el-col :span="11">
            <el-form-item label="招标编号" prop="sectionId">
              <el-input v-model="form.sectionId" disabled placeholder="请输入招标编号" />
            </el-form-item>
          </el-col>
          <el-col :span="11" :offset="1">
            <el-form-item label="招标名称" prop="sectionName">
              <el-input v-model="form.sectionName" disabled placeholder="请输入招标名称" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="11">
            <el-form-item label="组织方式" prop="bidmethod">
              <el-select v-model="form.bidmethod"  placeholder="请选择组织方式">
                <el-option
                  v-for="dict in dict.type.sys_bidmethos"
                  :key="dict.value"
                  :label="dict.label"
                  :value="Number(dict.value)">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="11" :offset="1">
            <el-form-item label="评标办法" prop="bidway">
              <el-select v-model="form.bidway" placeholder="请选择评标办法">
                <el-option
                  v-for="dict in dict.type.sys_bidway"
                  :key="dict.value"
                  :label="dict.label"
                  :value="Number(dict.value)">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="23">
            <el-form-item label="资质设置" prop="qualify">
              <el-input v-model="form.qualify" type="textarea" placeholder="请输入内容" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="11">
            <el-form-item label="公告开始时间" title="公告开始时间" prop="annBengin">
              <el-date-picker clearable
                v-model="form.annBengin"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="请选择公告开始时间">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="11" :offset="1">
            <el-form-item label="公告截止时间" title="公告截止时间" prop="annEnd">
              <el-date-picker clearable
                v-model="form.annEnd"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="请选择公告截止时间">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="11">
            <el-form-item label="开标时间" prop="open">
              <el-date-picker clearable
                v-model="form.open"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="请选择开标时间">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="11" :offset="1">
            <el-form-item label="开标地点" prop="openArea">
              <el-select v-model="form.openArea" placeholder="请选择开标地点">
                <el-option
                  v-for="dict in dict.type.sys_openarea"
                  :key="dict.value"
                  :label="dict.label"
                  :value="Number(dict.value)">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="11">
            <el-form-item label="估算金额" prop="planprice">
              <el-input class="pirce" v-model="form.planprice" disabled placeholder="请输入估算金额" /> 元
            </el-form-item>
          </el-col>
          <el-col :span="11" :offset="1">
            <el-form-item label="是否电子标" prop="online">
              <el-radio-group v-model="form.online">
                <el-radio :label="Number(dict.value)" v-for="dict in dict.type.is_switch" :key="dict.value">{{ dict.label }}</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="open = false">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 投标信息 -->
    <el-dialog
      :title="bidTitle"
      :visible.sync="bidOpen"
      v-loading="upload.isUploading"
      element-loading-text="投标信息导入中，请稍后..."
      element-loading-spinner="el-icon-loading"
      element-loading-background="rgba(0, 0, 0, 0.8)"
      width="46%" append-to-body
      :close-on-click-modal="false">

      <el-form :model="tenderDialog.queryParams" ref="tenderQueryForm" size="small" :inline="true" label-width="98px">
        <el-form-item label="投标单位名称" prop="tname" title="投标单位名称">
          <el-input v-model="tenderDialog.queryParams.tname" placeholder="请输入投标单位名称" clearable @clear="handleTenderQuery"  @keyup.enter.native="handleTenderQuery" />
        </el-form-item>
        <el-form-item label="是否中标" prop="state">
          <el-select v-model="tenderDialog.queryParams.state" clearable @clear="handleTenderQuery" placeholder="请选择是否中标" @change="handleTenderQuery">
            <el-option
              v-for="dict in dict.type.is_switch"
              :key="dict.value"
              :label="dict.label"
              :value="Number(dict.value)">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleTenderQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetTenderQuery">重置</el-button>
        </el-form-item>
      </el-form>

      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button
            type="primary"
            plain
            icon="el-icon-plus"
            size="mini"
            @click="handleTenderAdd"
            v-hasPermi="['system:tender:add']"
          >新增</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button
            type="success"
            plain
            icon="el-icon-edit"
            size="mini"
            :disabled="tenderDialog.single"
            @click="handleTenderUpdate"
            v-hasPermi="['system:tender:edit']"
          >修改</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button
            type="danger"
            plain
            icon="el-icon-delete"
            size="mini"
            :disabled="tenderDialog.multiple"
            @click="handleTenderDelete"
            v-hasPermi="['system:tender:remove']"
          >删除</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button
            type="warning"
            plain
            icon="el-icon-download"
            size="mini"
            @click="handleTenderExport"
            v-hasPermi="['system:tender:export']"
          >导出投标单位</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button type="warning" icon="el-icon-download" size="mini" v-hasPermi="['system:tender:download']" plain @click="handleExportTemplate">下载模板</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-upload
            class="upload-demo"
            ref="upload"
            :limit="1"
            accept=".xlsx, .xls"
            :action="upload.url"
            :headers="upload.headers"
            :data="upload.data"
            :on-success="handleFileSuccess"
            :on-error="handleFileError"
            :on-progress="handleFileUploadProgress">
            <el-button type="primary" icon="el-icon-upload2" size="mini" v-hasPermi="['system:tender:import']" plain>导入投标单位</el-button>
          </el-upload>
        </el-col>
      </el-row>

      <el-table v-loading="tenderDialog.loading" :data="tenderDialog.list" @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column label="投标单位名称" align="center" prop="tname"  show-overflow-tooltip width="200"/>
        <el-table-column label="投标金额" align="center" prop="tprice"  show-overflow-tooltip width="200">
          <template slot-scope="scope">
            <span>{{ scope.row.tprice }} 元</span>
          </template>
        </el-table-column>
        <el-table-column label="是否中标" align="center" prop="state"  show-overflow-tooltip width="100">
          <template slot-scope="scope">
            <el-tag :type="scope.row.state == 2 ? 'danger' : 'success'">
              <dict-tag :options="dict.type.is_switch" :value="scope.row.state"/>
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleTenderUpdate(scope.row)"
              v-hasPermi="['system:tender:edit']"
            >修改</el-button>
            <el-button
              size="mini"
              type="text"
              icon="el-icon-delete"
              @click="handleTenderDelete(scope.row)"
              v-hasPermi="['system:tender:remove']"
            >删除</el-button>
          </template>
        </el-table-column>
      </el-table>

      <pagination
        v-show="tenderDialog.total>0"
        :total="tenderDialog.total"
        :page.sync="tenderDialog.queryParams.pageNum"
        :limit.sync="tenderDialog.queryParams.pageSize"
        @pagination="getTenderList"
      />
      <!-- 添加或修改投标信息对话框 -->
      <el-dialog :title="tenderDialog.title" :visible.sync="tenderDialog.open" width="44%" append-to-body :close-on-click-modal="false">
        <el-form ref="tenderForm" :model="tenderDialog.form" :rules="tenderDialog.rules" label-width="98px">
          <el-row>
            <el-col :span="11">
              <el-form-item label="投标单位名称" title="投标单位名称" prop="tname">
                <el-input v-model="tenderDialog.form.tname" placeholder="请输入投标单位名称" />
              </el-form-item>
            </el-col>
            <el-col :span="11" :offset="1">
              <el-form-item label="投标金额" prop="tprice">
                <el-input  class="pirce" v-model="tenderDialog.form.tprice" placeholder="请输入投标金额" /> 元
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="11">
              <el-form-item label="是否中标" prop="state">
                <el-select v-model="tenderDialog.form.state" placeholder="请选择是否中标">
                  <el-option
                    v-for="dict in dict.type.is_switch"
                    :key="dict.value"
                    :label="dict.label"
                    :value="Number(dict.value)">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="23">
              <el-form-item label="备注" prop="remark">
                <el-input type="textarea" :row="4" v-model="tenderDialog.form.remark" placeholder="请输入备注" />
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>

        <div slot="footer" class="dialog-footer">
          <el-button type="primary" @click="submitTenderForm">确 定</el-button>
          <el-button @click="tenderCancel">取 消</el-button>
        </div>
      </el-dialog>


      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="bidOpen = false">确 定</el-button>
        <el-button @click="bidOpen = false">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 中标公示 -->
    <el-dialog :title="publicity.title" :visible.sync="publicity.open" width="30%" append-to-body :close-on-click-modal="false">
      <el-form ref="publicityForm" :model="publicity.form" :rules="publicity.rules" label-width="78px">
        <el-row>
          <el-col :span="23">
            <el-form-item label="公示时间" prop="bidnotice">
              <el-date-picker clearable
                v-model="publicity.form.bidnotice"
                type="date"
                format="yyyy-MM-dd"
                value-format="yyyy-MM-dd"
                placeholder="请选择公示时间">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>

      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitPublicityForm">确 定</el-button>
        <el-button @click="publicity.open = false">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 查看详情 -->
    <el-dialog class="section-detail-dialog" :title="sectionDetail.title" :visible.sync="sectionDetail.open" width="70%" append-to-body :close-on-click-modal="false">
      <el-row>
        <el-col :span="23">
          <el-tabs type="border-card"  v-model="sectionDetail.tabName">
            <el-tab-pane label="所属项目" name="project">
              <el-form ref="sectionForm" :model="sectionDetail.projectInfo" label-width="96px">
                <el-row>
                  <el-col :span="7">
                    <el-form-item label="部门名称:">
                      <span>{{ sectionDetail.projectInfo.deptName }}</span>
                    </el-form-item>
                  </el-col>
                  <el-col :span="7" :offset="1">
                    <el-form-item label="项目编号:">
                      <span>{{ sectionDetail.projectInfo.pid }}</span>
                    </el-form-item>
                  </el-col>
                  <el-col :span="7" :offset="1">
                    <el-form-item label="项目名称:">
                      <span>{{ sectionDetail.projectInfo.pname }}</span>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="7">
                    <el-form-item label="所属板块:">
                      <span>{{ sectionDetail.projectInfo.plateName }}</span>
                    </el-form-item>
                  </el-col>
                  <el-col :span="7" :offset="1">
                    <el-form-item label="委托单位:">
                      <span>{{ sectionDetail.projectInfo.clientName }}</span>
                    </el-form-item>
                  </el-col>
                  <el-col :span="7" :offset="1">
                    <el-form-item label="资金来源:">
                      <dict-tag :options="dict.type.sys_nego_source" :value="sectionDetail.projectInfo.sourcefunds"/>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="7">
                    <el-form-item label="部门负责人:">
                      <span>{{ sectionDetail.projectInfo.leader }}</span>
                    </el-form-item>
                  </el-col>
                  <el-col :span="7" :offset="1">
                    <el-form-item label="项目负责人:">
                      <span>{{ sectionDetail.projectInfo.assistant }}</span>
                    </el-form-item>
                  </el-col>
                  <el-col :span="7" :offset="1">
                    <el-form-item label="甲方负责人:">
                      <span>{{ sectionDetail.projectInfo.jf }}</span>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="7">
                    <el-form-item label="甲方联系电话:" title="甲方联系电话">
                      <span>{{ sectionDetail.projectInfo.jfPhone }}</span>
                    </el-form-item>
                  </el-col>
                  <el-col :span="7" :offset="1">
                    <el-form-item label="备案号:">
                      <span>{{ sectionDetail.projectInfo.recordid ? sectionDetail.projectInfo.recordid : '无' }}</span>
                    </el-form-item>
                  </el-col>
                  <el-col :span="7" :offset="1">
                    <el-form-item label="备案时间:">
                      <span>{{ sectionDetail.projectInfo.recordTime ? sectionDetail.projectInfo.recordTime : '无' }}</span>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="7">
                    <el-form-item label="委托时间:">
                      <span>{{ sectionDetail.projectInfo.clientTime }}</span>
                    </el-form-item>
                  </el-col>
                  <el-col :span="7" :offset="1">
                    <el-form-item label="组织方式:">
                      <dict-tag :options="dict.type.sys_bidmethos" :value="sectionDetail.projectInfo.bidmethod"/>
                    </el-form-item>
                  </el-col>
                  <el-col :span="7" :offset="1">
                    <el-form-item label="招标类别:">
                      <dict-tag :options="dict.type.sys_bidcategory" :value="sectionDetail.projectInfo.bidcategory"/>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="7">
                    <el-form-item label="工程类别:">
                      <dict-tag v-if="sectionDetail.projectInfo.enginer" :options="dict.type.sys_enginer" :value="sectionDetail.projectInfo.enginer"/>
                      <span v-else>无</span>
                    </el-form-item>
                  </el-col>
                  <el-col :span="7" :offset="1">
                    <el-form-item label="估算金额:">
                      <span>{{ sectionDetail.projectInfo.planprice }}</span> 元
                    </el-form-item>
                  </el-col>
                  <el-col :span="7" :offset="1">
                    <el-form-item label="是否外揽:">
                      <dict-tag :options="dict.type.is_switch" :value="sectionDetail.projectInfo.decide"/>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="7">
                    <el-form-item label="是否依法:">
                      <dict-tag :options="dict.type.is_switch" :value="sectionDetail.projectInfo.law"/>
                    </el-form-item>
                  </el-col>
                  <el-col :span="7" :offset="1">
                    <el-form-item label="控制价:">
                      <span>{{ sectionDetail.projectInfo.controlprice }}</span> 元
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="23">
                    <el-form-item label="招标范围或主要技术参数:" title="招标范围或主要技术参数">
                      <span>{{ sectionDetail.projectInfo.tcpa }}</span>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="23">
                    <el-form-item label="备注:">
                      <span>{{ sectionDetail.projectInfo.remark ? sectionDetail.projectInfo.remark : '无' }}</span>
                    </el-form-item>
                  </el-col>
                </el-row>
              </el-form>
            </el-tab-pane>
            <el-tab-pane label="标段信息" name="section">
              <el-form ref="sectionForm" :model="sectionDetail.form" label-width="96px">
                <el-row>
                  <el-col :span="7">
                    <el-form-item label="招标编号:">
                      <span>{{ sectionDetail.form.sectionId }}</span>
                    </el-form-item>
                  </el-col>
                  <el-col :span="7" :offset="1">
                    <el-form-item label="招标名称:">
                      <span>{{ sectionDetail.form.sectionName }}</span>
                   </el-form-item>
                  </el-col>
                  <el-col :span="7" :offset="1">
                    <el-form-item label="组织方式:">
                      <dict-tag :options="dict.type.sys_bidmethos" :value="sectionDetail.form.bidmethod"/>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="7">
                    <el-form-item label="评标办法:">
                      <dict-tag :options="dict.type.sys_bidway" :value="sectionDetail.form.bidway"/>
                    </el-form-item>
                  </el-col>
                  <el-col :span="15" :offset="1">
                    <el-form-item label="资质设置:">
                      <span>{{ sectionDetail.form.qualify }}</span>
                   </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="7">
                    <el-form-item label="公告开始时间:" title="公告开始时间">
                      <span>{{ sectionDetail.form.annBengin }}</span>
                    </el-form-item>
                  </el-col>
                  <el-col :span="7" :offset="1">
                    <el-form-item label="公告截止时间:" title="公告截止时间">
                      <span>{{ sectionDetail.form.annEnd }}</span>
                   </el-form-item>
                  </el-col>
                  <el-col :span="7" :offset="1">
                    <el-form-item label="开标时间:">
                      <span>{{ sectionDetail.form.open }}</span>
                   </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="7">
                    <el-form-item label="开标地点:">
                      <dict-tag :options="dict.type.sys_openarea" :value="sectionDetail.form.openArea"/>
                    </el-form-item>
                  </el-col>
                  <el-col :span="7" :offset="1">
                    <el-form-item label="估算金额:">
                      <span>{{ sectionDetail.form.planprice }}</span> 元
                   </el-form-item>
                  </el-col>
                  <el-col :span="7" :offset="1">
                    <el-form-item label="是否电子标:">
                      <dict-tag :options="dict.type.is_switch" :value="sectionDetail.form.online"/>
                   </el-form-item>
                  </el-col>
                </el-row>
              </el-form>
            </el-tab-pane>
            <el-tab-pane label="投标信息" name="tender">
              <el-table :data="sectionDetail.form.tenderList" max-height="500">
                <el-table-column label="序号" type="index" width="55" align="center" />
                <el-table-column label="投标单位名称" align="center" prop="tname"  show-overflow-tooltip width="130"/>
                <el-table-column label="投标金额" align="center" prop="tprice"  show-overflow-tooltip width="140"/>
                <el-table-column label="中标金额" align="center" prop="prepareMoney"  show-overflow-tooltip width="140"/>
                <el-table-column label="是否中标" align="center" prop="state"  show-overflow-tooltip width="120">
                  <template slot-scope="scope">
                    <el-tag :type="scope.row.state == 0 ? 'danger' : 'success'">
                      <dict-tag :options="dict.type.is_switch" :value="scope.row.state"/>
                    </el-tag>
                  </template>
                </el-table-column>
                <el-table-column label="备注" align="center" prop="remark"  show-overflow-tooltip>
                  <template slot-scope="scope">
                    <span v-if="scope.row.remark">{{ scope.row.remark }}</span>
                    <span v-else>暂无备注</span>
                  </template>
                </el-table-column>
              </el-table>
            </el-tab-pane>
          </el-tabs>
        </el-col>
      </el-row>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="sectionDetailCancel">确 定</el-button>
        <el-button @click="sectionDetailCancel">取 消</el-button>
      </div>
    </el-dialog>

    <el-dialog :title="stopContinue.title" :visible.sync="stopContinue.open" width="34%" append-to-body :close-on-click-modal="false">
      <el-form ref="continueForm" :model="stopContinue.form" :rules="stopContinue.rules" label-width="98px">
        <el-row>
          <el-col :span="23">
            <el-form-item label="中止类型" prop="sectionProgress">
              <el-select v-model="stopContinue.form.sectionProgress" placeholder="请选择中止类型">
                <el-option
                  v-for="dict in dict.type.section_stop"
                  :key="dict.value"
                  :label="dict.label"
                  :value="Number(dict.value)">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="23">
            <el-form-item label="中止原因" prop="stopCause">
              <el-input type="textarea" :rows="2" placeholder="请输入中止原因" v-model="stopContinue.form.stopCause"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="23">
            <el-form-item label="下次开标时间" prop="nextTime" title="下次开标时间">
              <el-date-picker clearable
                v-model="stopContinue.form.nextTime"
                type="date"
                format="yyyy-MM-dd"
                value-format="yyyy-MM-dd"
                placeholder="请选择下次开标时间">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitContinueForm">确 定</el-button>
        <el-button @click="stopContinue.open = false">取 消</el-button>
      </div>
    </el-dialog>


  </div>
</template>

<script>
import { listSection, getSection, updateSection, stopContinue } from "@/api/projectManage/sectionList"
import { listTender, getTender, delTender, addTender, updateTender } from "@/api/sectionManage/tender"
import { mapGetters } from "vuex"
import { getToken } from "@/utils/auth"
export default {
  name: "Section",
  dicts: ['sys_bidmethos', 'sys_openarea', 'sys_bidway', 'is_switch', 'section_progress', 'sys_bidcategory', 'sys_nego_source', 'sys_enginer', 'section_stop'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 标段列表表格数据
      sectionList: [],
      // 标段详情
      sectionDetail: {
        tabName: 'project',
        open: false,
        title: '标段详情',
        form: {},
        projectInfo: {}
      },
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        sectionId: null,
        sectionName: null,
        bidcategory: null,
        bidmethod: null,
        open: null,
        sectionProgress: null
      },
      // 表单参数
      form: {},
      rules: {
        bidmethod: [
          { required: true, message: "组织方式不能为空", trigger: "change" }
        ],
        bidway: [
          { required: true, message: "评标办法不能为空", trigger: "change" }
        ],
        qualify: [
          { required: true, message: "资质设置不能为空", trigger: "blur" }
        ],
        annBengin: [
          { required: true, message: "公告开始时间不能为空", trigger: "change" }
        ],
        annEnd: [
          { required: true, message: "公告截止时间不能为空", trigger: "change" }
        ],
        open: [
          { required: true, message: "开标时间不能为空", trigger: "change" }
        ],
        openArea: [
          { required: true, message: "开标地点不能为空", trigger: "change" }
        ],
        online: [
          { required: true, message: "是否电子标不能为空", trigger: "change" }
        ]
      },
      // 投标信息相关
      /* 投标信息导入参数 */
      upload: {
        isUploading: false,
        // 是否更新已经存在的用户数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传携带参数
        data: {
          id: null,
          sectionProgress: null
        },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/system/tender/importData"
      },
      bidTitle: '',
      bidOpen: false,
      tenderDialog: {
        loading: false,
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          tname: null,
          sid: null,
          state: null
        },
        total: 0,
        list: [],
        ids: [],
        form: {},
        rules: {
          tname: [
            { required: true, message: "投标单位名称不能为空", trigger: "blur" }
          ],
          tprice: [
            { required: true, message: "投标金额不能为空", trigger: "blur" }
          ],
          state: [
            { required: true, message: "是否中标不能为空", trigger: "change" }
          ]
        },
        open: false,
        title: ''
      },
      publicity: {
        title: '',
        open: false,
        form: {
          bidnotice: null
        },
        rules: {
          bidnotice: [
            { required: true, message: "公示时间不能为空", trigger: "change" }
          ]
        },
        list: []
      },
      stopContinue: {
        title: '',
        open: false,
        form: {
          stopCause: '',
          nextTime: '',
          sectionProgress: ''
        },
        rules: {
          sectionProgress: [
            { required: true, message: "中止类型不能为空", trigger: "change" }
          ],
          stopCause: [
            { required: true, message: "中止原因不能为空", trigger: "change" }
          ]
        }
      }
    };
  },
  computed: {
    ...mapGetters(['roles', 'userInfo'])
  },
  created() {
    console.log('userInfo', this.userInfo)
    if (this.roles.indexOf('fg_gf') > -1) {
      // 分管工程服务
      this.queryParams.bidcategorys = [0, 2]
    } else if (this.roles.indexOf('fg_h') > -1) {
      // 分管货物
      this.queryParams.bidcategorys = [1]
    } else {
      this.queryParams.bidcategorys = null
    }
    // this.queryParams.bidcategorys = this.userInfo.userId == 128 ? [0, 2] : this.userInfo.userId == 129 ? [1] : null
    this.getList()
  },
  methods: {
    /** 查询标段列表列表 */
    getList() {
      this.loading = true;
      listSection(this.queryParams).then(response => {
        this.sectionList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 处理页码连续
    indexMethod(index) {
      return (index + 1) + (this.queryParams.pageNum - 1) * this.queryParams.pageSize
    },
    // 表单重置
    reset() {
      this.form = {
        projectId: null,
        sectionId: null,
        sectionName: null,
        bidmethod: null,
        qualify: null,
        annBengin: null,
        annEnd: null,
        open: null,
        openArea: null,
        bidway: null,
        planprice: null,
        online: null,
        sectionProgress: 1
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm")
      this.handleQuery()
    },
    handleEdit(row) {
      this.reset()
      this.title = `${this.form.sectionProgress == 0 ? '发布公告' : '修改公告'}`
      getSection(row.id).then(response => {
        this.form = response.data
        this.open = true
      });
    },
    handleDetail(row) {
      getSection(row.id).then(response => {
        if (response.code == 200) {
          this.sectionDetail.form = response.data
          this.sectionDetail.projectInfo = response.data.projectInfo
          this.sectionDetail.open = true
        } else {
          this.$modal.msgError(response.msg)
        }
      })
    },
    // 中止
    handleContinue(row) {
      this.resetContinue()
      this.stopContinue.form.id = row.id
      this.stopContinue.title = '标段中止'
      this.stopContinue.open = true
    },
    // 提交中止表单
    submitContinueForm() {
      this.$refs['continueForm'].validate(async vaild => {
        if (vaild) {
          const res = await stopContinue(this.stopContinue.form)
          if (res.code == 200) {
            this.stopContinue.open = false
            this.resetContinue()
            this.$modal.msgSuccess('中止成功')
            this.getList()
          } else {
            this.$modal.msgError(res.msg)
          }
        }
      })
    },
    // 中止表单重置
    resetContinue() {
      this.stopContinue.form = {
        id: '',
        stopCause: '',
        nextTime: '',
        sectionProgress: ''
      }
    },
    submitForm() {
      this.form.sectionProgress = this.form.sectionProgress == 0 ? 1 : this.form.sectionProgress
      this.$refs['sectionForm'].validate(async vaild => {
        if (vaild) {
          console.log('this.form', this.form)
          const res = await updateSection(this.form)
          if (res.code == 200) {
            this.$modal.msgSuccess(`${this.form.sectionProgress == 0 ? '发布公告成功' : '修改公告成功'}`)
            this.open = false
            this.getList()
          } else {
            this.$modal.msgError(res.msg)
          }
        } else {
          this.$modal.msgWarning('请完善表单必填内容')
        }
      })
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/section/export', {
        ...this.queryParams
      }, `section_${new Date().getTime()}.xlsx`)
    },
    // 投标信息
    handleImport(row) {
      this.bidTitle = '投标信息'
      this.upload.data.id = row.id
      this.tenderDialog.queryParams.sid = row.id
      this.upload.data.sectionProgress = row.sectionProgress == 1 ? 2 : row.sectionProgress
      console.log('this.upload.data', this.upload.data)
      this.getTenderList()
      this.bidOpen = true
    },
    getPublicityList(row) {
      const queryParams = {
        sid: row.id,
        pageNum: 1,
        pageSize: 1000,
        state: 1
      }
      listTender(queryParams).then(response => {
        if (response.code == 200) {
          this.publicity.list = response.rows
        } else {
          this.publicity.list = []
        }
      })
    },
    hidePublicityList() {
      this.publicity.list = null
    },
    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      if (response.code == 200) {
        this.$refs.upload.clearFiles();
        this.$modal.msgSuccess('导入成功')
        this.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.msg + "</div>", "导入结果", { dangerouslyUseHTMLString: true });
        this.handleSectionProgress()
        this.getTenderList()
      } else {
        this.$modal.msgError(response.msg)
      }
      this.upload.isUploading = false;
      
    },
    handleFileError(error) {
      this.$modal.msgError(error)
    },
    /** 导出按钮操作 */
    handleExportTemplate() {
      this.download('system/tender/importTemplate', {
      }, `tender_template_${new Date().getTime()}.xlsx`)
    },
    // 中标公示
    handlePublicity(row) {
      this.publicity.title = `中标公示`
      this.publicity.open = true
      this.publicity.form.bidnotice = row.bidnotice ? row.bidnotice : null
      this.publicity.form.id = row.id
      this.publicity.form.sectionProgress = row.sectionProgress == 2 ? 3 : row.sectionProgress
    },
    // 公示确定
    submitPublicityForm() {
      this.$refs['publicityForm'].validate(async vaild => {
        if (vaild) {
          const res = await updateSection(this.publicity.form)
          if (res.code == 200) {
            this.$modal.msgSuccess(`${this.publicity.form.sectionProgress > 3 ? '修改中标公示成功' : '发布中标公示成功'}`)
            this.publicity.open = false
            this.getList()
          } else {
            this.$modal.msgError(res.msg)
          }
        } else {
          this.$modal.msgWarning('请完善表单必填内容')
          
        }
      })
    },
    /** 投标单位增 删 改 查 */
    getTenderList() {
      this.tenderDialog.loading = true
      listTender(this.tenderDialog.queryParams).then(response => {
        this.tenderDialog.list = response.rows
        this.tenderDialog.total = response.total
        this.tenderDialog.loading = false
      })
    },
    // 搜索
    handleTenderQuery() {
      this.tenderDialog.queryParams.pageNum = 1
      this.getTenderList()
    },
    // 重置
    resetTenderQuery() {
      this.resetForm("tenderQueryForm")
      this.handleTenderQuery()
    },
    handleSelectionChange(selection) {
      this.tenderDialog.ids = selection.map(item => item.id)
      this.tenderDialog.single = selection.length!==1
      this.tenderDialog.multiple = !selection.length
    },
    handleTenderAdd(row) {
      this.resetTender();
      this.tenderDialog.form.sid = this.upload.data.id
      this.tenderDialog.form.sectionProgress = this.upload.data.sectionProgress
      this.tenderDialog.open = true;
      this.tenderDialog.title = "添加投标信息";
    },
     /** 修改按钮操作 */
     handleTenderUpdate(row) {
      this.resetTender();
      const id = row.id || this.tenderDialog.ids
      getTender(id).then(response => {
        this.tenderDialog.form = response.data
        this.tenderDialog.open = true
        this.tenderDialog.title = "修改投标信息"
      })
    },
    handleTenderDelete(row) {
      const ids = row.id || this.tenderDialog.ids
      this.$modal.confirm('是否确认删除投标信息编号为"' + ids + '"的数据项？').then(function() {
        return delTender(ids)
      }).then(() => {
        this.getTenderList()
        this.$modal.msgSuccess("删除成功")
      }).catch(() => {})
    },
    /** 导出按钮操作 */
    handleTenderExport() {
      this.download('system/tender/export', {
        ...this.tenderDialog.queryParams
      }, `tender_${new Date().getTime()}.xlsx`)
    },
    resetTender() {
      this.tenderDialog.form = {
        id: null,
        sid: null,
        tname: null,
        tprice: null,
        state: null,
        remark: null
      }
      this.resetForm("tenderForm")
    },
    // 取消按钮
    tenderCancel() {
      this.tenderDialog.open = false
      this.resetTender()
    },
    submitTenderForm() {
      this.$refs["tenderForm"].validate(async valid => {
        if (valid) {
          if (this.tenderDialog.form.id != null) {
            updateTender(this.tenderDialog.form).then(response => {
              this.$modal.msgSuccess("修改成功")
              this.tenderDialog.open = false
              this.getTenderList()
            })
          } else {
            addTender(this.tenderDialog.form).then(response => {
              this.$modal.msgSuccess("新增成功")
              this.tenderDialog.open = false
              this.getTenderList()
            })
          }
          // 之前没有招标单位
          this.handleSectionProgress()
        }
      })
    },
    // 修改招标进度
    async handleSectionProgress() {
      if (this.tenderDialog.total > 0) return
      const res = await updateSection(this.upload.data)
      if (res.code == 200) {
        this.$modal.msgSuccess('招标进度修改成功')
        this.getList()
      } else {
        this.$modal.msgSuccess(res.msg)
      }
    },
    sectionDetailCancel() {
      this.sectionDetail.tabName = 'project'
      this.sectionDetail.form = {}
      this.sectionDetail.projectInfo = {}
      this.sectionDetail.open = false
    },
    async copyText(textToCopy) {
      // navigator clipboard 需要https等安全上下文
      if (navigator.clipboard && window.isSecureContext) {
        // navigator clipboard 向剪贴板写文本
        navigator.clipboard.writeText(textToCopy).then(() => {
          this.$modal.msgSuccess('复制成功！')
        })
      } else {
        // 创建text area
        let textArea = document.createElement("textarea");
        textArea.value = textToCopy;
        // 使text area不在viewport，同时设置不可见
        textArea.style.position = "absolute";
        textArea.style.opacity = '0';
        textArea.style.left = "-999999px";
        textArea.style.top = "-999999px";
        document.body.appendChild(textArea);
        textArea.focus();
        textArea.select();
        let res = new Promise((res, rej) => {
          res(() => {
            document.execCommand('copy')
            textArea.remove();
          })
          rej(false)
        })
        res.then(res => {
          res();
          this.$modal.msgSuccess('复制成功！')
        }).catch(error => {
          this.$modal.msgError('复制失败！')
        })
      }
    }
  }
};
</script>

<style lang="scss" scoped>
::v-deep .el-dialog{
  .el-date-editor, .el-input, .el-select {
    width: 100%;
  }
  .el-pagination {
    .el-date-editor, .el-input, .el-select {
      width: auto;
    }
  }
  .el-dialog__body {
    padding: 30px 10px 30px 30px;
  }
  .el-form-item__label {
    max-width: 100px; /* 你可以根据需要调整这个值 */
    white-space: nowrap; /* 防止文字换行 */
    overflow: hidden; /* 超出部分隐藏 */
    text-overflow: ellipsis; /* 文字溢出时显示省略号 */
  }
  .is-disabled{
    .el-textarea__inner, .el-input__inner {
      color: #333333;
    }
    .el-radio__label {
      color: #333333;
    }
    .el-radio__inner {
      border-color: #333333;
      &::after {
        background: #333333;
      }
    }
  }
  .pirce {
    width: 92%;
  }
}
.bid-dialog-header {
  display: flex;
  > .el-button {
    margin-right: 20px;
  }
}
.bidTable {
  margin-top: 20px;
}
::v-deep .el-upload-list {
  display: none !important;
}
// .popper-class-name {
//   margin: 0 10px 0 10px;
// }
::v-deep .el-popover__reference-wrapper {
  display: inline-block;
  margin: 0 10px 0 10px;
}
.section-detail-title {
  font-size: 16px;
  color: #333333;
  font-weight: bold;
  margin-bottom: 20px;
}

::v-deep .el-tabs {
  .el-tabs__item {
    font-size: 16px;
    font-weight: bold;
    color: #333333;
  }
}
</style>
